package client;

import static client.Config.getHost;
import logic.Document;
import logic.Template;
import net.SocketList;
import net.SocketLogon;
import net.SocketReporter;
import net.SocketRetriever;
import net.datagramme.DatagrammeRemoteMethodInvocator;
import net.retrievers.Retriever;
import net.rmi.List;
import net.rmi.Logon;
import net.rmi.Reporter;
import server.GlobalConfig;

public class DatagrammeFactory extends Factory {

	private SocketRetriever<Document> socketRetriever;
	private SocketLogon socketLogon;
	private SocketReporter socketReporter;
	private SocketRetriever<Template> socketRetriever2;
	private SocketList socketList;

	@Override
	public
	Retriever<Document> getDocumentRetriever() {
		if (socketRetriever == null)
			socketRetriever = new SocketRetriever<Document>(Document.class, new DatagrammeRemoteMethodInvocator(
					getHost(), GlobalConfig.UDP_DOCUMENT_RETR_PORT));
		return socketRetriever;
	}

	@Override
	public
	Logon getLogon() {
		if (socketLogon == null)
			socketLogon = new SocketLogon(new DatagrammeRemoteMethodInvocator(getHost(), GlobalConfig.UDP_LOGON_PORT));
		return socketLogon;
	}

	@Override
	public
	Reporter getReporter() {
		if (socketReporter == null)
			socketReporter = new SocketReporter(new DatagrammeRemoteMethodInvocator(getHost(),
					GlobalConfig.UDP_REPORTER_PORT));
		return socketReporter;
	}

	@Override
	public
	Retriever<Template> getTemplateRetriever() {
		if (socketRetriever2 == null)
			socketRetriever2 = new SocketRetriever<Template>(Template.class, new DatagrammeRemoteMethodInvocator(
					getHost(), GlobalConfig.UDP_TEMPLATE_RETR_PORT));
		return socketRetriever2;
	}

	@Override
	public
	List getList() {
		if (socketList == null)
			socketList = new SocketList(new DatagrammeRemoteMethodInvocator(getHost(), GlobalConfig.UDP_LIST_PORT));
		return socketList;
	}

}
